array2
array2
Precondition
pre safety: length0 ≥ 0 safety: length1 ≥ 0 safety: length0 *? length1 >=? 0
Type Parameters
Fields
the underlying one dimensional array
multidimensional indices are mapped to one dimensional indices as follows:
[x,y] -> [x * length1 + y]
resulting in the order:
arr[0,0], arr[0,1], arr[0,2], ..., arr[1,0], arr[1,1], arr[1,2], ...,
arr[2,0], arr[2,1], arr[2,2], ...
multidimensional indices are mapped to one dimensional indices as follows:
[x,y] -> [x * length1 + y]
resulting in the order:
arr[0,0], arr[0,1], arr[0,2], ..., arr[1,0], arr[1,1], arr[1,2], ...,
arr[2,0], arr[2,1], arr[2,2], ...
Functions
create a string representation of this array including all the string
representations of its contents, separated by ',' and enclosed in '['
and ']'. Arrays in inner dimensions are grouped using '[' and ']'.
representations of its contents, separated by ',' and enclosed in '['
and ']'. Arrays in inner dimensions are grouped using '[' and ']'.
dynamic_apply -- apply `f.call` to `Any.this`'s dynamic type and value
This can be used to perform operation on values depending on their dynamic
type.
Here is an example that takes a `Sequence Any` that may contain boxed values
of types `i32` and `f64`. We can now write a feature `get_f64` that extracts
these values converted to `f64` and build a function `sum` that sums them up
as follows:
This can be used to perform operation on values depending on their dynamic
type.
Here is an example that takes a `Sequence Any` that may contain boxed values
of types `i32` and `f64`. We can now write a feature `get_f64` that extracts
these values converted to `f64` and build a function `sum` that sums them up
as follows:
Get the dynamic type of this instance. For value instances `x`, this is
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
get a list of tuples indices and elements in this array
all pairs of indices: (0,0), (0,1), (0,2), .. (length0-1, length1-1)
indices range in first dimension
indices range in second dimension
convenience prefix operator to create a string from a value.
This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
Type Features
string representation of this type to be used for debugging.
result has the form "<name>", but this might change in the future
result has the form "<name>", but this might change in the future
create an array2 from a Sequence of a Sequence of elements
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.
Note: Typechecking is undecidable when 'type' is a type, Mark B. Reinhold, 1989
see: https://dspace.mit.edu/bitstream/handle/1721.1/149366/MIT-LCS-TR-458.pdf?sequence=6
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.
Note: Typechecking is undecidable when 'type' is a type, Mark B. Reinhold, 1989
see: https://dspace.mit.edu/bitstream/handle/1721.1/149366/MIT-LCS-TR-458.pdf?sequence=6
(a array2 array2.type.T, b array2 array2.type.T) => bool[Redefinition of property.equatable.type.equality]¶
(a array2 array2.type.T, b array2 array2.type.T)
=>
bool[Redefinition of property.equatable.type.equality]
¶equality of two arrays2 is true iff `a` and `b` have the same dimensions and for all
`i in indices0` and `j in indices1` we have `a[i][j] = b[i][j]`.
For performance, this will compare the length of the arrays first.
This is defined only if T : property.equatable, it will result in a compile-time panic
if this is not the case.
`i in indices0` and `j in indices1` we have `a[i][j] = b[i][j]`.
For performance, this will compare the length of the arrays first.
This is defined only if T : property.equatable, it will result in a compile-time panic
if this is not the case.
create hash code for this array2.
This should satisfy the following condition:
(T.equality a b) : (T.hash_code a = T.hash_code b)
This will result in a compile-time `panic` in case T : property.hashable does not hold.
The algorithm used here is a variation of (XXXHash)[https://xxhash.com] as used in
(Python's tuple)[https://github.com/python/cpython/blob/849a80ec412c36bbca5d400a7db5645b8cf54f1f/Objects/tupleobject.c#L305]:
we start with a constant `hash_prime1`
for each value:
we take its hash code * `hash_prime2` and add it
then we rotate by `hash_rotate`
and multiply by `hash_prime3`
This should satisfy the following condition:
(T.equality a b) : (T.hash_code a = T.hash_code b)
This will result in a compile-time `panic` in case T : property.hashable does not hold.
The algorithm used here is a variation of (XXXHash)[https://xxhash.com] as used in
(Python's tuple)[https://github.com/python/cpython/blob/849a80ec412c36bbca5d400a7db5645b8cf54f1f/Objects/tupleobject.c#L305]:
we start with a constant `hash_prime1`
for each value:
we take its hash code * `hash_prime2` and add it
then we rotate by `hash_rotate`
and multiply by `hash_prime3`
Is this type assignable to a type parameter with constraint `T`?
The result of this is a compile-time constant that can be used to specialize
code for a particular type.
it is most useful in conjunction with preconditions or `if` statements as in
or
The result of this is a compile-time constant that can be used to specialize
code for a particular type.
it is most useful in conjunction with preconditions or `if` statements as in
or
NOT implemented, calling this fails at compile time
There is no natural total ordering for two-dimensional arrays
There is no natural total ordering for two-dimensional arrays
name of this type, including type parameters, e.g. 'option (list i32)'.
array(length0, length1) -- two-dimensional immutable array
array provides two-dimensional immutable arrays. These are actually
one-dimensional immutable arrays with an additional access function with
two index parameters.
array provides two-dimensional immutable arrays. These are actually
one-dimensional immutable arrays with an additional access function with
two index parameters.
convenience prefix operator to create a string from a value.
This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913
This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913
Get a type as a value.
This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.
`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.
This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.
`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.
Applicable universe features
These are features in universe, that have an argument with a type constraint that matches this features type and can therefore be used with it.
equals -- feature that compares two values using the equality relation
defined in their type
defined in their type
hash of a value
infix = -- infix operation as shorthand for 'equals'
infix = -- infix operation as shorthand for 'equals'
is `a` contained in `Set` `s`?
This should usually be called using type inference as in
This should usually be called using type inference as in
is `a` not contained in `Set` `s`?
This should usually be called using type inference as in
This should usually be called using type inference as in
infix ≟ -- infix operation as shorthand for 'equals'
memoize `f`.
wraps f so that f will only be called once for every unique input.
The term "memoization" was coined by Donald Michie in 1968 and
is derived from the Latin word "memorandum" ("to be remembered"),
usually truncated as "memo" in American English, and thus carries
the meaning of "turning a function into something to be remembered".
https://en.wikipedia.org/wiki/Memoization
example:
wraps f so that f will only be called once for every unique input.
The term "memoization" was coined by Donald Michie in 1968 and
is derived from the Latin word "memorandum" ("to be remembered"),
usually truncated as "memo" in American English, and thus carries
the meaning of "turning a function into something to be remembered".
https://en.wikipedia.org/wiki/Memoization
example:
0.099dev (GIT hash 02118e9cbed77f3897084a4a507da3f11ac8881e)
array provides two-dimensional immutable arrays. These are actually
one-dimensional immutable arrays with an additional access function with
two index parameters.